<?php 
defined('IN_ADMIN') or exit('No permission resources.');
include $this->admin_tpl('header');
?> 

<script language="javascript" type="text/javascript" src="<?php echo JS_PATH;?>commoncheck.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo JS_PATH;?>open_window.class.js"></script>
<body onload="contractcheck()">
<div class="txt_head_frame">
	<span class="txt_frame_title">修改合同</span>
</div>
<div id="main_content">
<form name="myform" action="?m=sale&c=contractmanage&a=edit" method="post" id="myform">
<input type="hidden" name="info[customer_id]" id="_N_id_"/>
<input type="hidden" name="info[contract_id]" value="<?php echo $contract_id?>" />
<div class="txt_content_frame">
	<div class="txt_content_box">
		<div class="txt_content_left">
			<div class="txt_text_left">合同名称:<span>[*]</span></div>
			<div class="txt_left_input"><input name="info[contract_name]" type="text" class="txt" id="contract_name" value="<?php echo $contract_name?>"/></div><span id="validatecrontact_name" class="validate"></span><br/><br/>
			<div class="txt_text_left">合同号:<span>[*]</span></div>
			<div class="txt_left_input"><input name="info[contract_num]" type="text" class="txt" id="contract_num" value="<?php echo $contract_num?>"/></div><span id="validatecontract_num" class="validate"></span><br/><br/>		
			<div class="txt_text_left">对应客户:<span>[*]</span></div>
			<div class="txt_left_input"><input  type="text" class="txt" disabled="disabled" id="_N_name_"  value="<?php echo $customer_name['customer_name']?>"/><a onclick="javascript:Open_window.winOpen(set_ajx_url('index.php?m=account&c=customermanage&a=search'))" href="javascript:void(0)"><img src="images/detail.png"></a></div><br/><br/>
            <div class="txt_text_left">分类:</div>
			<div class="txt_left_input">
            <select name="info[contract_type]" class="select">
            <?php 
            	foreach ($option_cache['contract_type'] as $key => $value) {
            ?>
			<option value="<?php echo $key?>" <?php echo $key == $contract_type ? 'selected' : ''?>><?php echo $value?></option>
			<?php 
            	}
			?>
			</select>
			</div><br/><br/>  
			<div class="txt_text_left">付款方式:</div>
			<div class="txt_left_input">
            <select name="info[contract_pay_mode]" class="select">
            <?php 
            	foreach ($option_cache['contract_pay_mode'] as $key => $value) {
            ?>
			<option value="<?php echo $key?>" <?php echo $key == $contract_pay_mode ? 'selected' : ''?>><?php echo $value?></option>
			<?php 
            	}
			?>
			</select>
			</div><br/><br/> 
			<div class="txt_text_left">合同金额:</div>
			<div class="txt_left_input"><input name="info[contract_sum]" type="text" class="txt" id="contract_sum" value="<?php echo $contract_sum?>"/></div><span id="validatecontract_sum" class="validate"></span><br/><br/> 
		</div>
	</div>
</div>

<div class="txt_btn">
	<input name="dosubmit" type="submit" class="txt_btn_a" value=" 保存 " />
</div>
</form>

</div>
<div class="txt_att">
	<form name="myform" action="?m=sale&c=contractmanage&a=upload" method="post" enctype="multipart/form-data">
			<div class="txt_attarea">
				<div class="txt_txtarea_text">&#12288;合同上传：</div>
				<div class="txt_txtarea_input">
				<div align="left">
				<input size="30" type="file" value=" 浏览 " name="file" id="file" >		
				</div><span id='response'></span>
				</div>
			</div>
	</form>
	<div class="txt_attarea" id="att_list"></div>
</div>
</body>
<script type="text/javascript">
<!--
var Open_window = new Open_window();
function contractcheck(){
	$('#contract_name').blur(function(){
		var validate = $('#validatecontact_name');
		if(isNotNull($(this).val())){	
			validate.html('<img src="images/true.gif" width=16 heigth=16>');
		} else {
			validate.html('<img src="images/false.gif" width=16 heigth=16>不能为空');	
		}
	});
}

/*附件列表*/
function att_list(){
	var url = window.location.pathname;
	$.ajax({
		url:url+'?'+set_ajx_url('m=sale&c=contractmanage&a=att_list_ajx&_contract_num=<?php echo $contract_num?>'),
		type:'post',
		dataType:'json',
		success:function(data){
			var html = "";
			for(var i = 0;i<data.length;i++){
				html += '<div><a  href="'+url+'?'+'m=sale&c=contractmanage&a=download&a_k='+data[i]['a_k']+'&ron_hash='+ron_hash+'">'+data[i]['filename']+'</a><a onclick="confirm(\'确定删除吗？\')? att_del('+data[i]['aid']+') :\'\'" href="javascript:void(0)"><img width="18" heigth="19" src="images/delete.gif" ></a></div>';
				}
			$('#att_list').html(html);
		}
	});
}
//'+url+'?'+'m=sale&c=contractmanage&a=file_delete&att_id='+data[i]['aid']+'&ron_hash='+ron_hash+'
function att_del(aid){
	var url = window.location.pathname;
	$.ajax({
		url:url+'?'+set_ajx_url('m=sale&c=contractmanage&a=file_delete&att_id='+aid),
		type:'post',
		dataType:'json',
		success:function(info){
			 if(info == '1'){
				 att_list();
			} else{
				alert('无法删除');
			}
		},error:function(){
			alert('asd');}
	});
	
}
(function(){
	att_list();
	var formdata = new FormData();
	$('#file').change(function(){ 
		var i = 0, len = this.files.length, file;
		for ( ; i < len; i++ ) {
			file = this.files[i];
			if (formdata) {
				formdata.append("file", file);
			}
			}
		
		var url = window.location.pathname;
		$('#response').html('<img src="images/onLoad.gif" width=16 heigth=16>上传中');
		$.ajax({
			url:url+'?'+set_ajx_url('m=sale&c=contractmanage&a=upload&_contract_num=<?php echo $contract_num?>'),
			type:'post', 
			data: formdata,
	        processData: false,
	        contentType: false,
			success:function(infor){
				if(infor == '1'){
					$('#file').val('');
					$('#response').html('');
					att_list();		
				} else {
					alert(infor);
					$('#response').html('');
				}				
			}
		});
	});
}());
//-->
</script>
</html>